package org.sgx.gwtjsutiltest.client;

import org.sgx.jsutil.client.JsArray;
import org.sgx.jsutil.client.JsFunction;
import org.sgx.jsutil.client.JsObject;
import org.sgx.jsutil.client.TestUtil;
import org.sgx.jsutil.client.jsfc.VV;

public class JsFunctionTest1 {
	int counter1=0;
	
	public void test1(TestUtil test ) {
		JsFunction f1 = JsFunction.create("return 'hello'; "); 
		String result1 = f1.applyString(null, null); 
		test.assertEquals(result1, "hello"); 
		
		test.assertEquals(counter1, 0); 
//		JsFunction f2 = JsFunctionUtil.toJsFunction(new VV() {		
//			@Override
//			public void call() {
//				counter1++;
//			}
//		}); 
		JsFunction f2 = new VV() {		
			@Override
			public void call() {
				counter1++;
			}
		}.toNative(); 
		f2.apply(null, null); 
		test.assertEquals(counter1, 1); 
		
		
		JsFunction sum = JsFunction.create("return arguments[0]+arguments[1]; " + "");
		test.assertTrue(sum.applyInteger(JsArray.create(1, 2)) == 3,
			"applyInteger1: " + sum.applyInteger(JsArray.create(1, 2)));
		;

		JsFunction fn1 = JsFunction.create("return arguments[0].prop2+arguments[0].prop1;" + "");
		result1 = fn1.applyString(JsArray.create(JsObject.one("prop1", 123)._("prop2", "hello")));
		test.assertTrue(result1 != null && result1.equals("hello123"), "applyInteger2: ");
		
		
		

	}
}
